package com.hema.auction.activity;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.hema.auction.R;
import com.hema.auction.base.BaseActivity;
import com.hema.auction.bean.SysUnits;
import com.hema.auction.utils.Constant;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 描述:主页广告页
 * 作者:john
 */
public class AdActivity extends BaseActivity {
    @BindView(R.id.iv_ad)
    ImageView ivAd;
    private SysUnits ad;

    private boolean newUser;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ad);
        ad = (SysUnits) getIntent().getSerializableExtra(Constant.EXTRA_AD);
        newUser = getIntent().getBooleanExtra(Constant.EXTRA_NEW_USER, false);
        if (newUser)
            ad.setImg(ad.getValue());
        ButterKnife.bind(this);
//        GlideUtils.load(this, ad.getImg(), ivAd);
        Glide.with(this).load(ad.getImg()).into(new SimpleTarget<Drawable>() {
            @Override
            public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
                ivAd.setImageDrawable(resource);
            }
        });
        ivAd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (newUser) {
                    intentTo(LoginActivity.class);
                } else {
                    switch (ad.getUrlType()) {//1跳H5，2跳详情，3跳充值
                        case 1:
                            Bundle bundle = new Bundle();
                            bundle.putString(Constant.EXTRA_URL, ad.getUrl());
                            intentTo(H5Activity.class, bundle);
                            break;
                        case 2:
                            bundle = new Bundle();
                            bundle.putString(Constant.EXTRA_GOOD_ID, ad.getUrl());
                            intentTo(GoodsDetailsActivity.class, bundle);
                            break;
                        case 3:
                            intentTo(RechargeActivity.class);
                            break;
                        default:
//                        bundle = new Bundle();
//                        bundle.putString(Constant.EXTRA_GOOD_ID, "101");
//                        intentTo(GoodsDetailsActivity.class, bundle);
                            break;
                    }
                }
                finish();
            }
        });
    }

    @OnClick(R.id.iv_close)
    public void onClick(View v) {
        finish();
    }
}
